package com.xian.serviceimpl;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailSendException;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

import com.xian.service.MailService;


@Service
public class MailServiceImp implements MailService {
	@Autowired
	private JavaMailSender sender;

	


	

	public void sendHtmlMail(String receive,String message)
			throws MessagingException, MailSendException {

		String html = "<html><head><meta http-equiv=\"content-type\" content=\"text/html;charset=\"utf-8\">" +
				"</head><body>" +
				message
				 + "</body></html>";
		MimeMessage msg = sender.createMimeMessage();
		// 指定编码为utf-8,同时标识为非marltipart 的消息
		MimeMessageHelper helper = new MimeMessageHelper(msg, false, "utf-8");
		helper.setFrom("1019288034@qq.com");
		helper.setTo(receive);
		helper.setSubject("来自校园闲置网消息");
		helper.setText(html, true);
		sender.send(msg);

	}

	public JavaMailSender getSender() {
		return sender; 
	}



	public void setSender(JavaMailSender sender) {
		this.sender = sender;
	}



	public void sendNotify(String message,String receive) throws MessagingException, MailSendException {
		String html = "<html><head><meta http-equiv=\"content-type\" content=\"text/html;charset=\"utf-8\"></head><body>"+message+ "</body></html>";
		MimeMessage msg = sender.createMimeMessage();
		// 指定编码为utf-8,同时标识为非marltipart 的消息
		MimeMessageHelper helper = new MimeMessageHelper(msg, false, "utf-8");
		helper.setFrom("1019288034@qq.com");
		helper.setTo(receive);
		helper.setSubject("新消息！");
		helper.setText(html, true);
		sender.send(msg);
	}

}
